package com.minelx.landisk.filesystem.core;

import com.minelx.landisk.filesystem.core.init.OpenPolicy;
import com.minelx.landisk.filesystem.core.provider.FS;
import com.minelx.landisk.filesystem.core.values.PathDescription;

import java.util.Objects;

public class Locator {

	private final FS fs;

	private final PathDescription location;

	public Locator(FS fs, PathDescription location) {
		this.fs = fs;
		this.location = location;
	}

	public File file(String path, OpenPolicy openPolicy) {
		return File.create(path(path), openPolicy);
	}

	public Directory dir(String path, OpenPolicy openPolicy) {
		return Directory.create(path(path), openPolicy);
	}

	public Path path(String path) {
		PathDescription concatPath = location.concat(PathDescription.from(path));
		return Path.create(fs, concatPath);
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;
		Locator locator = (Locator) o;
		return location.equals(locator.location);
	}

	@Override
	public int hashCode() {
		return Objects.hash(location);
	}

	@Override
	public String toString() {
		return "Locator{" +
				"locatedAt=" + location +
				", pathMethodProviderFactory=" + fs +
				'}';
	}
}
